import tkinter

import cv2
import matplotlib.pyplot as plt
import numpy as np
def videoCapture(luJing,jianGe,quYu1,quYu2,quYu3,quYu4,baoCun):


    # 视频路径
    vc = cv2.VideoCapture(luJing)

    # rval是否读取成功 frame读取视频的帧
    rval, frame = vc.read()

    fps = vc.get(cv2.CAP_PROP_FPS)
    frame_all = vc.get(cv2.CAP_PROP_FRAME_COUNT)

    # 视频基本信息
    print("视频FPS:", fps, '每秒')
    print("视频总帧数:", frame_all)
    print("视频时长:", (frame_all / fps), '秒')
    # 每隔300帧 10S保存一张图片
    frame_interval = int(int(jianGe)*fps)
    print("共需保存：", (int(frame_all / frame_interval)), "张图片")
    # 统计当前帧
    frame_count = 1
    # 保存图片个数
    count = 0

    # 循环根据间隔帧数进行抽样保存
    while rval:
        rval, frame = vc.read()

        if frame_count % frame_interval == 0:
            # '.\video\waterPic\7.22\7.22-20,0.1\'
            filename = baoCun + '/picture-' + str(count) + '.jpg'

            count += 1
            print("当前保存第:", count, '张图片到  ', baoCun)
            # 选择视频截取区域 frame = frame[300:650, 650:1150]
            frame = frame[int(quYu1):int(quYu2), int(quYu3):int(quYu4)]
            print(quYu1,quYu2,quYu3,quYu4)

            capture = vc
            frame_height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
            frame_width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
            print(frame_height,frame_width)
            cv2.imwrite(filename, frame)
            # print("---------------------------------------")

        frame_count += 1

    # 关闭视频文件
    vc.release()
    print("总共保存了", count, "张图片")
